package com.ewhale.feitengguest.presenter.shop.mine

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.ShopAuthDto
import com.ewhale.feitengguest.view.shop.mine.SMineView
import com.ewhale.feitengguest.view.shop.mine.ShopAuthView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

/**
 * 作者：SimGa
 * 日期：2020/1/3
 * 时间：10:18
 * 包名：com.ewhale.feitengguest.presenter.shop.mine
 */
class ShopAuthPresenter : IPresenter() {


    fun getAuthInfo() {
        mView.showProLoading()
        request(1, ApiHelper.USER_API.authentication, null)
    }
    fun commitAuInfo(shopType: Int?, type: Int, name: String, phone: String, address: String,idNumber: String) {
        val params = HashMap<String,Any>()
        params["type"] = type
        params["name"] = name
        params["phone"] = phone
        params["address"] = address
        params["certificateNumber"] = idNumber
//        if(shopType == 2){
//            params["businessImg"] = "$idCardFront,$idCardRear"
//        }else{
//            params["certificateFrontImg"] = idCardFront
//            params["certificateBackImg"] = idCardRear
//        }
        mView.showProLoading()
        request(2, ApiHelper.USER_API.saveAuthentication(params), null)
    }
    override fun <T> onNext(postCode: Int, result: T?, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> {
                if (result == null) {
                    mView.showErrorMessage(postCode, "null", "")
                } else {
                    (mView as ShopAuthView).showAuthInfo(result as ShopAuthDto)
                }
            }
            2 -> (mView as ShopAuthView).commitSuccess()
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }


}
